package com.liu.yubi.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lqh
 * @since 2025-05-31 18:51
 * redis配置类
 */
@Configuration
//加了这个注解之后 会自动去匹配配置文件中的属性值
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {

    /**
     * redis地址
     */
    private String host;

    /**
     * 端口
     */
    private Integer port;

    /**
     * spring在启动的时候 会自动创建一个redissonClient对象
     */
    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config ();
        config.useSingleServer ()
                .setAddress("redis://"+host+":"+port)
                .setDatabase(1);
        return Redisson.create (config);

    }
}
